feat: Expose metrics API to Objective-C #7339
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧
🤖 This preview updates automatically when you update the PR. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #7339 +/- ##
=============================================
- Coverage 85.182% 84.857% -0.325%
=============================================
Files 475 471 -4
Lines 28560 28483 -77
Branches 12410 12299 -111
=============================================
- Hits 24328 24170 -158
- Misses 4185 4267 +82
+ Partials 47 46 -1
... and 27 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
philprime
left a comment
There was a problem hiding this comment.
I am going to raise an internal discussion on this, because there might have been a miscommunication, so please hold back from further adapting this PR for now
|
Closing this for now as the Metrics API is intended to remain a Swift-only interface. |
📜 Description
This PR introduces
SentryMetricswrapper class that bridges the Swift-only metrics API (count, distribution, gauge) to Objective-C.This pattern was used because there is no way to make the underlying types
@objc-compatible:SentryUnitis a Swift enum with associated valuesSentryAttributeValueis a Swift protocolSentryMetricsApiis a generic struct which also cannot be `@objcEven though the static type of
SentrySDK.metricschanged fromSentryMetricsApiProtocoltoSentryMetrics, read access remains fully backward-compatible becauseSentryMetricsconforms toSentryMetricsApiProtocol, so existing Swift call sites and variables typed as the protocol continue to work.The actual breaks would only be:
SentrySDK.metrics = MyCustomImpl()let m: SentryMetricsApi<...> = SentrySDK.metricsHowever, neither of these look like supported use-cases.
💡 Motivation and Context
The Unreal Engine plugin uses
sentry-cocoainternally via Objective-C which previously had no access to the metrics API. This change enables metrics calls from any Objective-C context by acceptingStringfor units and[String: Any]for attributes converting them to the Swift-native types internally.Related items:
💚 How did you test it?
Manually emitted counter, gauge, and distribution metrics in Unreal Engine using a patched version of the Cocoa SDK in the plugin.
📝 Checklist
You have to check all boxes before merging:
sendDefaultPIIis enabled.